<template>
  <div ref="container" class="detail-view">
    <div class="produc-view">
      <div class="nav-list" :style="{ height: productStyle.height }">
        <div
          v-for="(item, i) in images"
          :key="i + 't'"
          class="nav-i"
          :style="imgStyle"
        >
          <img :src="item" alt="" />
        </div>
      </div>
      <div class="zoom-img" :style="productStyle">
        <zoom-on-hover :img-normal="min" />
      </div>
      <div class="right-view">
        <div class="r-view-box" :style="boxStyle">
          <div class="title">奢华意大利140支双股皮马棉四件套</div>
          <div class="desc">奢华意大利140支双股皮马棉四件套</div>
          <div class="price">190.68元</div>
          <div class="color"><img :src="min" alt="" /></div>
          <div class="c-title">尺寸</div>
          <div class="c-view">
            <div class="tag">150mmX200mm</div>
            <div class="tag">150mmX200mm</div>
            <div class="tag">150mmX200mm</div>
          </div>
          <div class="btn">选购</div>
          <div class="text">天喜</div>
          <div class="text-d">
            我们对深思熟虑的设计非常着迷——从最具创新性的材料到将必需品
            变成痴迷的小细节。我们与世界顶级工厂合作，只使用 型号 Fgkus372
          </div>
          <Collapse
            :collapseData="collapseData"
            v-model:activeKey="key"
            @change="onChange"
          />
        </div>
      </div>
    </div>
    <div class="swiper-view">
      <div class="title-view">
        <div class="title">畅销产品</div>
        <div class="right">
          <icons class="icon" name="jiantou2" />
          <icons class="icon" name="jiantou" />
        </div>
        <!-- 如果需要导航按钮 -->
      </div>
      <swiper
        :slidesPerView="4"
        :spaceBetween="15"
        :freeMode="true"
        :pagination="{
          clickable: true,
        }"
        :navigation="true"
        :modules="modules"
        class="mySwiper"
      >
        <swiper-slide>
          <img class="swiper-img" src="../../assets/image/1.jpeg" alt="" />
          <div class="title">奢华意大利140支双股皮马棉四件套</div>
          <div class="desc-box">
            <div class="desc">奢华意大利140支双股皮马棉四件套</div>
            <div class="price">190.68元</div>
          </div>
        </swiper-slide>
        <swiper-slide>
          <img class="swiper-img" src="../../assets/image/1.jpeg" alt="" />
          <div class="title">奢华意大利140支双股皮马棉四件套</div>
          <div class="desc-box">
            <div class="desc">奢华意大利140支双股皮马棉四件套</div>
            <div class="price">190.68元</div>
          </div>
        </swiper-slide>
        <swiper-slide>
          <img class="swiper-img" src="../../assets/image/1.jpeg" alt="" />
          <div class="title">奢华意大利140支双股皮马棉四件套</div>
          <div class="desc-box">
            <div class="desc">奢华意大利140支双股皮马棉四件套</div>
            <div class="price">190.68元</div>
          </div>
        </swiper-slide>
        <swiper-slide>
          <img class="swiper-img" src="../../assets/image/1.jpeg" alt="" />
          <div class="title">奢华意大利140支双股皮马棉四件套</div>
          <div class="desc-box">
            <div class="desc">奢华意大利140支双股皮马棉四件套</div>
            <div class="price">190.68元</div>
          </div>
        </swiper-slide>
        <swiper-slide>
          <img class="swiper-img" src="../../assets/image/1.jpeg" alt="" />
          <div class="title">奢华意大利140支双股皮马棉四件套</div>
          <div class="desc-box">
            <div class="desc">奢华意大利140支双股皮马棉四件套</div>
            <div class="price">190.68元</div>
          </div>
        </swiper-slide>
        <swiper-slide>
          <img class="swiper-img" src="../../assets/image/1.jpeg" alt="" />
          <div class="title">奢华意大利140支双股皮马棉四件套</div>
          <div class="desc-box">
            <div class="desc">奢华意大利140支双股皮马棉四件套</div>
            <div class="price">190.68元</div>
          </div>
        </swiper-slide>
      </swiper>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { computed, ref, onMounted, watchEffect } from "vue";
import { useRouter, useRoute } from "vue-router";
import Collapse from "@/components/Collapse/index.vue";
import { Swiper, SwiperSlide } from "swiper/swiper-vue";
import { FreeMode, Navigation } from "swiper/modules";

import ZoomOnHover from "@/components/ImagMax/ZoomOnHover.vue";
// Import Swiper styles
import "swiper/swiper.css";
const route = useRoute();
const value = computed(() => route.params.id);
const router = useRouter();
const modules = [FreeMode, Navigation];
const min = require("../../assets/image/1.jpeg");
const images = ref([
  require("../../assets/image/1.jpeg"),
  require("../../assets/image/2.jpeg"),
  require("../../assets/image/3.jpeg"),
  require("../../assets/image/4.jpeg"),
  require("../../assets/image/5.jpeg"),
  require("../../assets/image/6.jpeg"),
]);
const collapseData = ref([
  {
    key: "1",
    header: "This is panel header 1",
    text: "A dog is a type of domesticated animal.Known for its loyalty and faithfulness,it can be found as a welcome guest in many households across the world.",
  },
  {
    key: "2",
    header: "This is panel header 2",
    text: `  A dog is a type of domesticated animal.Known for its loyalty and faithfulness,it can be found as a welcome guest in many households across the world.
  A dog is a type of domesticated animal.Known for its loyalty and faithfulness,it can be found as a welcome guest in many households across the world.213213213213123213213213123213213213213213213123213213213123213213213213213213123213213213123213213213213213213123213213213123213213`,
  },
  {
    key: "3",
    header: "This is panel header 3",
    text: "A dog is a type of domesticated animal.Known for its loyalty and faithfulness,it can be found as a welcome guest in many households across the world.",
  },
]);
const container = ref<HTMLElement | null>(null);
const productStyle = ref({ minWidth: "1030px", height: "1364px" });
const imgStyle = ref({ width: "190px", height: "250px" });
const boxStyle = ref({ width: "420px" });
const activeKey = ref(["1"]);
watchEffect(() => {
  console.log("activeKey:", activeKey.value);
});
const key = ref("1");
watchEffect(() => {
  console.log("key:", key.value);
});
function onChange(key: any) {
  console.log("change:", key);
}
/**
 * @description: 页面跳转实例
 * @param {*} url
 * @return {*}
 * @author: cool panda
 */
const toPage = (url: string) => {
  router.push(url);
};
const handleResize: ResizeObserverCallback = (entries) => {
  if (entries[0].target) {
    const containerWidth = entries[0].contentRect.width;
    const w = containerWidth * 0.53;
    const r = 1030 / 1364;
    const w1 = containerWidth * 0.09;
    const r1 = 190 / 250;
    productStyle.value = { minWidth: w + "px", height: w / r + "px" };
    imgStyle.value = { width: w1 + "px", height: w1 / r1 + "px" };
    boxStyle.value = { width: containerWidth * 0.21 + "px" };
  }
};
onMounted(() => {
  const resizeObserver = new ResizeObserver(handleResize);
  if (container.value) {
    resizeObserver.observe(container.value);
  }

  return () => {
    if (container.value) {
      resizeObserver.unobserve(container.value);
    }
    resizeObserver.disconnect();
  };
});
</script>
<style lang="less" scoped>
.detail-view {
  margin-top: 20px;
  width: 100%;
  .produc-view {
    width: 100%;
    display: flex;
    .nav-list {
      padding: 0 20px;
      overflow-y: auto;
      .nav-i {
        margin-bottom: 10px;
        img {
          width: 100%;
          height: 100%;
          object-fit: cover;
        }
      }
    }
    .zoom-img {
      width: 53%;
      height: 1364px;
    }
    .right-view {
      flex: 1;
      display: flex;
      justify-content: center;
      .r-view-box {
        text-align: left;
        .title {
          font-size: 24px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #000000;
          line-height: 33px;
        }
        .desc {
          margin-top: 8px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #555555;
          line-height: 20px;
        }
        .price {
          margin-top: 14px;
          font-size: 14px;
          font-family: PingFangSC-Semibold, PingFang SC;
          font-weight: 600;
          color: #000000;
          line-height: 20px;
        }
        .color {
          margin-top: 60px;
          margin-bottom: 30px;
          img {
            width: 56px;
            height: 56px;
            border-radius: 50%;
            border: 2px solid #000000;
          }
        }
        .c-title {
          font-size: 15px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #000000;
          line-height: 21px;
        }
        .c-view {
          display: flex;
          flex-wrap: wrap;
          .tag {
            font-size: 14px;
            font-family: PingFangSC-Regular, PingFang SC;
            font-weight: 400;
            color: #000000;
            line-height: 20px;
            margin-right: 50px;
          }
        }
        .btn {
          display: flex;
          justify-content: center;
          align-items: center;
          margin: 44px 0 13px;
          width: 100%;
          height: 50px;
          background: #000000;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #ffffff;
          line-height: 20px;
        }
        .text {
          display: inline;
          font-size: 15px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #000000;
          line-height: 21px;
          padding-bottom: 5px;
          border-bottom: 1px solid #000000;
        }
        .text-d {
          margin-top: 14px;
          font-size: 14px;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
          color: #000000;
          line-height: 20px;
          margin-bottom: 60px;
        }
      }
    }
  }
  .swiper-view {
    margin-top: 100px;
    padding: 0 60px;
    .title-view {
      display: flex;
      justify-content: space-between;
      .title {
        text-align: left;
        font-size: 38px;
        font-family: PingFangSC-Semibold, PingFang SC;
        font-weight: 600;
        color: #000000;
        line-height: 53px;
        margin-bottom: 30px;
      }
      .icon {
        width: 38px;
        height: 26px;
        margin-left: 20px;
      }
    }
    .mySwiper {
      text-align: left;
      .swiper-img {
        width: 100%;
        object-fit: cover;
      }
      .title {
        font-size: 14px;
        font-family: PingFangSC-Regular, PingFang SC;
        font-weight: bold;
        color: #000000;
        line-height: 25px;
        width: 100%;
        white-space: nowrap; /* 防止文字换行 */
        overflow: hidden; /* 隐藏溢出部分 */
        text-overflow: ellipsis; /* 显示省略号 */
      }
      .desc {
        flex: 1;
        font-size: 12px;
        font-family: PingFangSC-Regular, PingFang SC;
        color: #b1b1b1;
        white-space: nowrap; /* 防止文字换行 */
        overflow: hidden; /* 隐藏溢出部分 */
        text-overflow: ellipsis; /* 显示省略号 */
      }
      .price {
        font-size: 12px;
        font-family: PingFangSC-Semibold, PingFang SC;
        color: #000000;
        line-height: 20px;
      }
      /*先去掉默认样式*/
    }
  }
}
</style>
<style>
.swiper-button-prev:after {
  display: none;
}
.swiper-button-next:after {
  display: none;
}
/*再自定义样式*/
.swiper-button-prev {
  width: 35px;
  height: 35px;
  background: url("../../assets/image/right.jpg") no-repeat;
  bottom: 15px;
}
.swiper-button-next {
  width: 35px;
  height: 35px;
  background: url("../../assets/image/right.jpg") no-repeat;
  bottom: 15px;
}
</style>
